package com.finger.crowd.controller;


import com.finger.crowd.entity.vo.DetailProjectVO;
import com.finger.crowd.entity.vo.PortalTypeVO;
import com.finger.crowd.entity.vo.ProjectVO;
import com.finger.crowd.service.api.ProjectService;
import com.finger.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.transform.Result;
import java.util.List;


// 作为被调用的远程方法，一定要加RestController或者是Response！！！！！！！！！！！！！！！！！！！
@RestController
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @RequestMapping("/get/all/portal/vo")
    public ResultEntity<List<PortalTypeVO>> getAllPortalProject() {

        try {
            List<PortalTypeVO> allPortalType = projectService.getAllPortalProject();

            return ResultEntity.successWithData(allPortalType);
        } catch (Exception exception) {

            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }

    }

    @RequestMapping("/save/project/vo/remote")
    public ResultEntity saveProjectVO(@RequestBody ProjectVO projectVO,
                                      @RequestParam("memberId") Integer memberId) {

        try {
            ResultEntity saveProjectVOResult = projectService.saveProjectVO(projectVO, memberId);

            return saveProjectVOResult;
        } catch (Exception exception) {
            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }
    }

    @RequestMapping("/get/detail/project/vo/remote")
    public ResultEntity<DetailProjectVO> getDetailProjectVO(@RequestParam("projectId") Integer projectId) {

        try {
            DetailProjectVO detailProjectVO = projectService.getDetailProjectVO(projectId);

            return ResultEntity.successWithData(detailProjectVO);

        } catch (Exception exception) {

            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }
    }


}
